package com.vishnu.main;

import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.vishnu.pojo.Department;
import com.vishnu.pojo.Emp;

public class PracticeOnManyToOne {
	public static void main(String[] args) {
		Configuration cfg =new Configuration();
		cfg.configure("hib.cfg.xml");
		SessionFactory sf=cfg.buildSessionFactory();
		Session hsession=sf.openSession();
		Transaction tx=hsession.beginTransaction();
	System.out.println("---------transaction started--------");
	
	Emp emp=new Emp();
	emp.setEno(3);
	emp.setName("vishnu");
	
	Emp emp2=new Emp();
	emp2.setEno(4);
	emp2.setName("vardhan");
	
	Department department1=new Department();
	department1.setDid(1);
	department1.setDeptName("R&D dep");
	department1.setLocation("banglore");
	Set empSet=new HashSet();
	empSet.add(emp);
	empSet.add(emp2);
	
	department1.setEmp(empSet);
	

	
	emp.setDid(department1);
	emp2.setDid(department1);
	hsession.save(department1);

	
	
	
	tx.commit();
	hsession.close();
	sf.close();
	}
}
